<?php
class Stock_receipt_product_model extends CI_Model
{
	public $tbl = 'stock_receipt_product';

	public function __contruct()
	{
		parent::__construct();	
	}

	public function GetAllProductByReceiptId($stock_receipt_id)
	{
		$queryString = "SELECT tblStockReceiptProduct.*, Product.Name AS ProductName
						FROM ( SELECT * FROM stock_receipt_product WHERE Stock_receipt_id = $stock_receipt_id) AS tblStockReceiptProduct
						JOIN Product ON tblStockReceiptProduct.ProductId = Product.Id";

		$query = $this->db->query($queryString);
		
		return $query->result();
	}
	
	public function Add($Stock_receipt_id)
	{
		$data = array(
			'Mount' => $this->input->post('Mount'),
			'Price' => $this->input->post('Price'),
			'Stock_receipt_id' => $Stock_receipt_id,
			'ProductId' => $this->input->post('ProductId')
			);

		return $this->db->insert($this->tbl, $data);
	}

	public function UpdateMountReal($id, $mountReal)
	{
		$data = array(
			'Mount_Real' => $mountReal
			);

		$this->db->where('Id', $id);//$id);

		$this->db->update($this->tbl, $data);
	}
}
?>